package org.chouy.utils.api;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;


import java.io.IOException;

import static java.security.CryptoPrimitive.SIGNATURE;

/**
 * @program: Yang
 * @description: 短信接口测试
 * @author: Zhouy
 * @create: 2019-01-07 10:36
 **/
public class MessageApiTest {

    private static final int TYPE_NORMAL = 0;
    public static final String NATION_CODE = "86";

    public static void sendMessage(){


        int appId = 1400178189;

        String appKey = "146657b1f4e873335190d0890357c75a";

        String[] phoneNumbers = {"15000214549"};

        int templateId = 7839;

        String smsSign = "腾讯云";

        String[] params = {"4646"};

        String msg = "腾讯科技";
        //msg = "【" + SIGNATURE + "】您正在验证手机号码，验证码为" + msg + "，请及时输入，验证    码5分钟内有效，感谢您的支持！";
        SmsSingleSender sender = new SmsSingleSender(appId,appKey);
        try {
            //SmsSingleSenderResult senderResult = sender.sendWithParam("86",phoneNumbers[0],templateId,params,smsSign,"","");
            SmsSingleSenderResult senderResult = sender.send(0,"86","15000214549",msg,"","");
            System.out.println(senderResult.errMsg);
            System.out.println(senderResult);
        } catch (HTTPException e) {
            System.out.println("Http响应错误");
            e.printStackTrace();
        } catch (JSONException e) {
            System.out.println("Json解析错误");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("网络IO错误");
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        sendMessage();
    }
}
